1575J - Jeopardy of Dropped Balls - CodeForces Solution


binary search brute force dsu implementation *1500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define sp " "
#define endl "\n"
#define mod 1000000007
const ll INF = 9e18;
#define debug(x) cout << #x << ":" << x << endl;
#define vi vector<ll>

ll grid[1005][1005];
void solve()
{
    ll n, m, k;
    cin >> n >> m >> k;

    for (ll r = 1; r <= n; r++)
    {
        for (ll c = 1; c <= m; c++)
            cin >> grid[r][c];
    }

    while (k--)
    {
        ll col;
        cin >> col;
        ll row = 1;
        while (true)
        {
            if (row == n + 1)
            {
                cout << col << " ";
                break;
            }
            if (grid[row][col] == 2)
                row++;
            else if (grid[row][col] == 1)
            {
                grid[row][col] = 2;
                col++;
            }
            else
            {
                grid[row][col] = 2;
                col--;
            }
        }
    }
    cout << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll test = 1;
    // cin >> test;
    while (test--)
    {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains